package model;


import java.util.LinkedList;
import java.util.Observable;

public class AdapterStack<E> extends Observable implements StackADT<E> {
	
	// instance variables 
	public LinkedList<E> S = new LinkedList<E>(); ; 

	public boolean isEmpty() { 
		
		return S.size()==0; 
	}
	
	public E pop()throws EmptyStackException{
		
		E element;
		
		if (isEmpty()){
			throw new EmptyStackException
			("Empty Stack: Cannot pop");}
		
		element = S.pop();
		// facilitates garbage collection
		return element;
	}
	
	
	public E peek()throws EmptyStackException{
		
		if (isEmpty()){
			throw new EmptyStackException
			("Stack is empty. Cannot obtain an element");}
		
		return S.peek();
	}
	
	public void push(E  element){
		
		S.push(element);
		
	}
	
	public int size(){
		
		return S.size();
	}
	
	public void update() {
		this.setChanged();
		this.notifyObservers();
	}
	
	
}
